package com.resume.crm01.service.impl;

import com.resume.crm01.mapper.CourseBookMapper;
import com.resume.crm01.model.CourseBook;
import com.resume.crm01.model.MonthIncome;
import com.resume.crm01.model.PageResult;
import com.resume.crm01.service.CourseBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CourseBookServiceImpl implements CourseBookService {
    @Autowired
    CourseBookMapper courseBookMapper;

    @Override
    public PageResult<CourseBook> findPageResult(CourseBook condition, int page, int pageSize) {

        //定义一个Map-参数先不放在map,后面再处理
        Map<String,Object> params = new HashMap<String,Object>();
        params.put("condition",condition);
        params.put("page",(page - 1) * pageSize);
        params.put("pageSize",pageSize);

        //定义结果
        PageResult<CourseBook> result = new PageResult<CourseBook>();

        result.setCode(0);
        result.setCount(courseBookMapper.findCountByMap(params));
        result.setData(courseBookMapper.findListByMap(params));
        return result;
    }

    @Override
    public void save(CourseBook book) {
        courseBookMapper.insert(book);
    }

    @Override
    public CourseBook findByBookId(String id) {
        return courseBookMapper.findByBookId(id);
    }

    @Override
    public void delete(String id) {
        courseBookMapper.deleteByBookId(id);
    }

    @Override
    public void update(CourseBook book) {
        courseBookMapper.update(book);
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return courseBookMapper.getMonthIncomes();
    }
}
